﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(AudioSource))]
public class Collctions : MonoBehaviour
{
    // 销毁音效
    public AudioSource deathAudio;

    // 碰撞体
    public Collider2D coll;

    // 精灵渲染
    private SpriteRenderer sp;

    // Start is called before the first frame update
    protected virtual void Start()
    {
        deathAudio = GetComponent<AudioSource>();
        sp = GetComponent<SpriteRenderer>();
    }

    // 销毁物体调用
    public void Death()
    {
        coll.enabled = false;
        sp.enabled = false;

        deathAudio.Play();
        Destroy(gameObject, 0.5f);     
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.tag == "Player")
        {
            Death();
        }
    }
}
